import 'package:audioplayers/audioplayers.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flick_video_player/flick_video_player.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/models/request/pager_request.dart';
import 'package:sainbainu/common/models/response/comment_response.dart';
import 'package:sainbainu/common/models/response/content_response.dart';
import 'package:sainbainu/common/repositories/comment_repository.dart';
import 'package:sainbainu/common/repositories/common_repository.dart';
import 'package:sainbainu/common/repositories/content_repository.dart';
import 'package:sainbainu/common/repositories/user_repository.dart';
import 'package:sainbainu/common/widgets/image_uploader.dart';
import 'package:sainbainu/common/widgets/recorder.dart';
import 'package:scroll_to_index/scroll_to_index.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';

class ContentDetailState {
  late ScrollController scrollController;

  late AutoScrollController autoScrollController;

  /// 内容仓库
  late ContentRepository contentRepository;

  late UserRepository userRepository;

  /// 内容id
  late int noteId;

  /// hero 动画需要的tag
  String? uniqueTag;
  String? userAvatar;

  /// 帖子详情
  ContentResponse contentInfo = ContentResponse();

  /// 视频播放器
  FlickManager? flickManager;

  /// 音频播放器
  AudioPlayer? audioPlayer;

  /// 音频播放
  final isAudioPlaying = false.obs;
  final audioSeconds = 0.obs;
  final playingUrl = ''.obs;
  int currentAudioMaxDuration = 0;

  /// ============================发布评论相关===================================
  /// 聚焦
  late FocusNode focusNode;

  /// 评论输入框是否显示
  var showCommentInput = false.obs;

  /// 评论输入框 key
  GlobalKey commentInputKey = GlobalKey();

  /// 评论输入框控制器
  late TextEditingController commentEditingController;

  /// 评论文本
  String commentText = '';

  /// 评论图片
  AssetEntity? commentImage;
  String? commentImageUrl;

  /// 评论图片上传控制器
  late ImageUploaderController imageUploaderController;

  /// 评论录音
  String? commentAudio;
  String? commentAudioUrl;

  /// 评论录音时长
  Duration? commentAudioDuration;

  /// 是否可提交评论
  bool get disabledCommentSubmit =>
      commentText.isEmpty && commentImage == null && commentAudio == null;

  /// 评论录音控制器
  late CustomRecorderController customRecorderController;

  /// 公共仓库
  late CommonRepository commonRepository;

  /// ============================评论列表相关===================================

  /// 评论刷新控制器
  late EasyRefreshController commentRefreshController;

  /// 回复评论刷新控制器
  late EasyRefreshController replyCommentRefreshController;

  /// 评论仓库
  late CommentRepository commentRepository;

  /// 评论分页请求
  late PagerRequest commentPagerRequest;

  /// 回复分页请求
  late PagerRequest replyCommentPagerRequest;

  /// 评论列表
  CommentListResponse commentListResponse = CommentListResponse(
    total: 0,
    rows: [],
  );

  /// 回复列表
  CommentListResponse replyCommentListResponse = CommentListResponse(
    total: 0,
    rows: [],
  );

  /// 评论是否有更多
  bool commentHasMore = false;

  /// 回复是否有更多
  bool replyCommentHasMore = false;

  /// 当前弹窗的父级评论
  CommentResponse? currentCommentInfo;
}
